﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SampleDataTools
{
    public class LightButton : Control
    {
        private System.Drawing.Drawing2D.PathGradientBrush PathBrush;
        public LightButton()
        {
            DoubleBuffered = true;
            System.Drawing.Drawing2D.GraphicsPath p = new System.Drawing.Drawing2D.GraphicsPath();
            p.AddEllipse(0.0f, 0.0f, 1.0f, 1.0f);
            PathBrush = new System.Drawing.Drawing2D.PathGradientBrush(p);
            PathBrush.CenterPoint = new PointF(0.35f, 0.35f);

            System.Drawing.Drawing2D.ColorBlend colorBlend = new System.Drawing.Drawing2D.ColorBlend(4);
            colorBlend.Colors[0] = Color.DarkGray;
            colorBlend.Colors[1] = Color.Gray;
            colorBlend.Colors[2] = Color.Snow;
            colorBlend.Colors[3] = Color.White;

            colorBlend.Positions[0] = 0.0f;
            colorBlend.Positions[1] = 0.3f;
            colorBlend.Positions[2] = 0.9f;
            colorBlend.Positions[3] = 1.0f;

            PathBrush.InterpolationColors = colorBlend;
        }

        public Color[] StatusColors { get; set; }

        public int CurrentStatus { get; set; }

        protected override void OnPaint(PaintEventArgs e)
        {
            Color active = Color.Gray;

            if (StatusColors != null && CurrentStatus >= 0 && CurrentStatus < StatusColors.Length)
            {
                active = StatusColors[CurrentStatus];
            }
            try
            {
                System.Drawing.Drawing2D.ColorBlend colorBlend = new System.Drawing.Drawing2D.ColorBlend(4);
                colorBlend.Colors[0] = active;
                colorBlend.Colors[1] = active;
                colorBlend.Colors[2] = Color.Snow;
                colorBlend.Colors[3] = Color.White;

                colorBlend.Positions[0] = 0.0f;
                colorBlend.Positions[1] = 0.3f;
                colorBlend.Positions[2] = 0.9f;
                colorBlend.Positions[3] = 1.0f;

                PathBrush.InterpolationColors = colorBlend;

                PathBrush.ResetTransform();
                PathBrush.ScaleTransform(Width, Height);

                // fill status
                e.Graphics.FillRectangle(PathBrush, ClientRectangle);

                // draw side
                e.Graphics.DrawEllipse(Pens.Black, Rectangle.Inflate(ClientRectangle, -1, -1));
            }
            catch (Exception)
            {
            }

        }
    }
}
